from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-27 14:10:37.894361
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 27, Mar, 2021
Time: 14:10:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.1198
Nobs: 243.000 HQIC: -47.8925
Log likelihood: 2869.03 FPE: 9.42836e-22
AIC: -48.4136 Det(Omega_mle): 6.55855e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448639 0.129099 3.475 0.001
L1.Burgenland 0.070823 0.063704 1.112 0.266
L1.Kärnten -0.216723 0.055015 -3.939 0.000
L1.Niederösterreich 0.085022 0.142245 0.598 0.550
L1.Oberösterreich 0.214838 0.132324 1.624 0.104
L1.Salzburg 0.263479 0.071407 3.690 0.000
L1.Steiermark 0.147590 0.093678 1.576 0.115
L1.Tirol 0.115184 0.062596 1.840 0.066
L1.Vorarlberg -0.032536 0.058055 -0.560 0.575
L1.Wien -0.082629 0.118988 -0.694 0.487
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.476827 0.154258 3.091 0.002
L1.Burgenland 0.006619 0.076118 0.087 0.931
L1.Kärnten 0.340757 0.065736 5.184 0.000
L1.Niederösterreich 0.115926 0.169966 0.682 0.495
L1.Oberösterreich -0.089096 0.158111 -0.564 0.573
L1.Salzburg 0.211870 0.085323 2.483 0.013
L1.Steiermark 0.133677 0.111933 1.194 0.232
L1.Tirol 0.135384 0.074795 1.810 0.070
L1.Vorarlberg 0.153278 0.069369 2.210 0.027
L1.Wien -0.472786 0.142176 -3.325 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.304013 0.062793 4.842 0.000
L1.Burgenland 0.093844 0.030985 3.029 0.002
L1.Kärnten -0.016955 0.026759 -0.634 0.526
L1.Niederösterreich 0.043712 0.069187 0.632 0.528
L1.Oberösterreich 0.294184 0.064361 4.571 0.000
L1.Salzburg 0.014721 0.034732 0.424 0.672
L1.Steiermark 0.016090 0.045564 0.353 0.724
L1.Tirol 0.068195 0.030446 2.240 0.025
L1.Vorarlberg 0.086215 0.028238 3.053 0.002
L1.Wien 0.101998 0.057875 1.762 0.078
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211527 0.064397 3.285 0.001
L1.Burgenland 0.020455 0.031776 0.644 0.520
L1.Kärnten 0.008673 0.027442 0.316 0.752
L1.Niederösterreich 0.047278 0.070954 0.666 0.505
L1.Oberösterreich 0.399754 0.066005 6.056 0.000
L1.Salzburg 0.081575 0.035619 2.290 0.022
L1.Steiermark 0.140204 0.046728 3.000 0.003
L1.Tirol 0.047753 0.031224 1.529 0.126
L1.Vorarlberg 0.081973 0.028959 2.831 0.005
L1.Wien -0.039076 0.059353 -0.658 0.510
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.519005 0.126013 4.119 0.000
L1.Burgenland 0.080091 0.062181 1.288 0.198
L1.Kärnten 0.008988 0.053700 0.167 0.867
L1.Niederösterreich -0.037022 0.138846 -0.267 0.790
L1.Oberösterreich 0.138622 0.129161 1.073 0.283
L1.Salzburg 0.052329 0.069701 0.751 0.453
L1.Steiermark 0.092898 0.091439 1.016 0.310
L1.Tirol 0.213593 0.061100 3.496 0.000
L1.Vorarlberg 0.033186 0.056668 0.586 0.558
L1.Wien -0.091885 0.116144 -0.791 0.429
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196439 0.096724 2.031 0.042
L1.Burgenland -0.022630 0.047728 -0.474 0.635
L1.Kärnten -0.019663 0.041219 -0.477 0.633
L1.Niederösterreich -0.030857 0.106574 -0.290 0.772
L1.Oberösterreich 0.430157 0.099141 4.339 0.000
L1.Salzburg 0.007426 0.053500 0.139 0.890
L1.Steiermark -0.011513 0.070186 -0.164 0.870
L1.Tirol 0.160879 0.046899 3.430 0.001
L1.Vorarlberg 0.058802 0.043496 1.352 0.176
L1.Wien 0.236817 0.089149 2.656 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.244690 0.121854 2.008 0.045
L1.Burgenland 0.019046 0.060129 0.317 0.751
L1.Kärnten -0.060806 0.051928 -1.171 0.242
L1.Niederösterreich -0.051652 0.134263 -0.385 0.700
L1.Oberösterreich 0.006940 0.124898 0.056 0.956
L1.Salzburg 0.076815 0.067400 1.140 0.254
L1.Steiermark 0.345473 0.088421 3.907 0.000
L1.Tirol 0.454865 0.059084 7.699 0.000
L1.Vorarlberg 0.146397 0.054797 2.672 0.008
L1.Wien -0.176737 0.112311 -1.574 0.116
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124096 0.143479 0.865 0.387
L1.Burgenland 0.051427 0.070799 0.726 0.468
L1.Kärnten -0.066354 0.061143 -1.085 0.278
L1.Niederösterreich 0.205364 0.158090 1.299 0.194
L1.Oberösterreich -0.022321 0.147063 -0.152 0.879
L1.Salzburg 0.206189 0.079361 2.598 0.009
L1.Steiermark 0.134838 0.104112 1.295 0.195
L1.Tirol 0.051067 0.069569 0.734 0.463
L1.Vorarlberg 0.096574 0.064522 1.497 0.134
L1.Wien 0.222272 0.132242 1.681 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.588756 0.077901 7.558 0.000
L1.Burgenland -0.040883 0.038440 -1.064 0.288
L1.Kärnten -0.027192 0.033197 -0.819 0.413
L1.Niederösterreich 0.007686 0.085834 0.090 0.929
L1.Oberösterreich 0.334169 0.079847 4.185 0.000
L1.Salzburg 0.017493 0.043089 0.406 0.685
L1.Steiermark -0.032250 0.056527 -0.571 0.568
L1.Tirol 0.087606 0.037772 2.319 0.020
L1.Vorarlberg 0.114087 0.035032 3.257 0.001
L1.Wien -0.040854 0.071800 -0.569 0.569
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136016 0.034340 0.160063 0.215572 0.054046 0.075604 -0.002139 0.155341
Kärnten 0.136016 1.000000 0.017683 0.203839 0.177231 -0.068501 0.156592 0.020467 0.306020
Niederösterreich 0.034340 0.017683 1.000000 0.248745 0.063942 0.291044 0.141044 0.031487 0.298654
Oberösterreich 0.160063 0.203839 0.248745 1.000000 0.301471 0.277052 0.087206 0.057727 0.133885
Salzburg 0.215572 0.177231 0.063942 0.301471 1.000000 0.153383 0.048844 0.092191 -0.003342
Steiermark 0.054046 -0.068501 0.291044 0.277052 0.153383 1.000000 0.112265 0.096236 -0.137322
Tirol 0.075604 0.156592 0.141044 0.087206 0.048844 0.112265 1.000000 0.163647 0.146368
Vorarlberg -0.002139 0.020467 0.031487 0.057727 0.092191 0.096236 0.163647 1.000000 0.004388
Wien 0.155341 0.306020 0.298654 0.133885 -0.003342 -0.137322 0.146368 0.004388 1.000000